<?php
session_start();
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

//从POST过来的signed_request中提取oauth2信息
if(!empty($_REQUEST["signed_request"])){
	$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY  );
	$data=$o->parseSignedRequest($_REQUEST["signed_request"]);
	if($data=='-2'){
		 die('签名错误!');
	}else{
		$_SESSION['oauth2']=$data;
	}
}

//判断用户是否授权
if (empty($_SESSION['oauth2']["user_id"])) {//若没有获取到access token，则发起授权请求
		echo  json_encode(array("code"=>0,"remark"=>"false"));
		exit;
} else {//若已获取到access token，则加载应用信息
		$c = new SaeTClientV2( WB_AKEY , WB_SKEY ,$_SESSION['oauth2']['oauth_token'] ,'' );
		
		if( isset($_REQUEST['jokecontent']) ) {
			
			$ret = $c->update( '#jokemall##笑话超市#'.$_REQUEST['jokecontent']." http://www.jokemall.cn/?sina" );	//发送微博
			if ( isset($ret['error_code']) && $ret['error_code'] > 0 ) {
				echo  json_encode(array("code"=>0,"remark"=>"false"));
			} else {
				echo  json_encode(array("code"=>1,"remark"=>"success"));
			}
	
		}
	    
}

?>
